package com.liuxy.javautil;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;

import android.os.Environment;

public class LogFileUtil {
	private static final String TAG = "MyTools.LogFileUtil";
	
	private static int LOGFILE_LENGTH=1024*1024*10;//10M
	private final static String LOGFILE_NAME="log.txt";
	public static void appendLog(String logStr){
		FileWriter writer = null;
		File file=new File(Environment.getExternalStorageDirectory(), LOGFILE_NAME);
		if (file.exists()&&file.length()>=LOGFILE_LENGTH) {
			file.delete();
		}
        try {
			writer=new FileWriter(file,true);
			String strDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ").format(System.currentTimeMillis());
			writer.write("\n"+strDate+logStr);
		} catch (IOException e) {
			e.printStackTrace();
		}finally{IOUtil.close(writer);}
	}
	
	private LogFileUtil(){
		/* cannot be instantiated */
		throw new UnsupportedOperationException(TAG+" cannot be instantiated");
	}
}